package net.jsoft.pms.entity.problem;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.annotations.GenericGenerator;

import net.jsoft.platform.core.util.json.CustomDateSerializer;
import net.jsoft.platform.security.entity.user.SysUser;
import net.jsoft.pms.entity.dept.Dept;

@Entity
@Table(name = "t_dzswj_problem")
public class ProblemTask implements Comparable<ProblemTask>, Serializable
{
    /**
     * 
     */
    private static final long serialVersionUID = -5290841630586808343L;
    private String id;
    //    private String optPerson;

    private SysUser optPerson;
    private String title;
    private String content;
    private String level;
    private Dept dept;
    private Date insertDate;
    //    private long versions;
    private String status;
    private Date dealDate;

    private Date startDate;
    private Date endDate;

    private String taskId;

    @Id
    @GeneratedValue(generator = "problemGenerator")
    @GenericGenerator(name = "problemGenerator", strategy = "assigned")
    public String getId()
    {
        return id;
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getStatus()
    {
        return status;
    }

    public void setStatus(String status)
    {
        this.status = status;
    }

    public String getTaskId()
    {
        return taskId;
    }

    public void setTaskId(String taskId)
    {
        this.taskId = taskId;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "optPerson")
    public SysUser getOptPerson()
    {
        return optPerson;
    }

    public void setOptPerson(SysUser optPerson)
    {
        this.optPerson = optPerson;
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    @Column(name = "content", length = 3000)
    public String getContent()
    {
        return content;
    }

    public void setContent(String content)
    {
        this.content = content;
    }

    public String getLevel()
    {
        return level;
    }

    public void setLevel(String level)
    {
        this.level = level;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "dept")
    public Dept getDept()
    {
        return dept;
    }

    public void setDept(Dept dept)
    {
        this.dept = dept;
    }

    //    public long getVersions()
    //    {
    //        return versions;
    //    }
    //
    //    public void setVersions(long versions)
    //    {
    //        this.versions = versions;
    //    }

    @JsonSerialize(using = CustomDateSerializer.class)
    public Date getDealDate()
    {
        return dealDate;
    }

    public void setDealDate(Date dealDate)
    {
        this.dealDate = dealDate;
    }

    @JsonSerialize(using = CustomDateSerializer.class)
    public Date getInsertDate()
    {
        return insertDate;
    }

    public void setInsertDate(Date insertDate)
    {
        this.insertDate = insertDate;
    }

    @Override
    public int hashCode()
    {
        return this.getId().hashCode();
    }

    @Override
    public boolean equals(Object obj)
    {
        ProblemTask pt = (ProblemTask) obj;

        if (obj != null && this.id.equals(pt.getId()))
        {
            return true;
        }
        else
        {
            return false;
        }

    }

    @Override
    public int compareTo(ProblemTask o)
    {
        try
        {
            int i = (int) (this.getDept().getId() - o.getDept().getId());
            if (i != 0)
            {
                return i;
            }

            if (this.getOptPerson() != null && o.getOptPerson() != null)
            {
                i = (int) (this.getOptPerson().getId() - o.getOptPerson().getId());
                if (i != 0)
                {
                    return i;
                }

            }

            i = this.getInsertDate().compareTo(o.getInsertDate());
            if (i != 0)
            {
                return i;
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return this.getId().compareTo(o.getId());
    }

    public Date getStartDate()
    {
        return startDate;
    }

    public void setStartDate(Date startDate)
    {
        this.startDate = startDate;
    }

    public Date getEndDate()
    {
        return endDate;
    }

    public void setEndDate(Date endDate)
    {
        this.endDate = endDate;
    }

}
